package com.gt.andr.tabactvttest;

import android.app.TabActivity;
import android.os.Bundle;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.widget.TabHost;

public class TabActivityTestActivity extends TabActivity implements android.view.GestureDetector.OnGestureListener{
	TabHost mTabHost;
	private GestureDetector gestureScanner;

	/**
	 * Called when the activity is first created.
	 * 
	 * @param savedInstanceState
	 *            the saved instance state
	 */
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		mTabHost = getTabHost();

		mTabHost.addTab(mTabHost.newTabSpec("tab_test1").setIndicator("TAB 1", getResources().getDrawable(R.drawable.icon))
				.setContent(R.id.textview1));
		mTabHost.addTab(mTabHost.newTabSpec("tab_test2").setIndicator("TAB 2").setContent(R.id.textview2));
		mTabHost.addTab(mTabHost.newTabSpec("tab_test3").setIndicator("TAB 3").setContent(R.id.textview3));

		mTabHost.setCurrentTab(0);
		gestureScanner = new GestureDetector(this);
	}

	@Override
	public boolean onTouchEvent(MotionEvent me) {
		return gestureScanner.onTouchEvent(me);
	}

	@Override
	public boolean onDown(MotionEvent e) {
		return true;
	}

	@Override
	public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

		System.out.println("1 \t" + e1.getX() + "," + e1.getY());
		System.out.println("2 \t" + e2.getX() + "," + e2.getY());
		System.out.println("VelocityX :" + velocityX);
		System.out.println("VelocityY :" + velocityY);
		float dispX = e2.getX() - e1.getX();
		float dispY = e2.getY() - e1.getY();
		if (Math.abs(dispX) >= 200 && Math.abs(dispY) <= 50) {
			// swipe ok
			if (dispX > 0) {
				// L-R swipe
				System.out.println("L-R swipe");
			} else {
				// R-L swipe
				System.out.println("R-L swipe");
			}
		}
		return true;
	}

	@Override
	public void onLongPress(MotionEvent e) {
	}

	@Override
	public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
		return true;
	}

	@Override
	public void onShowPress(MotionEvent e) {
	}

	@Override
	public boolean onSingleTapUp(MotionEvent e) {
		return true;
	}

}